package com.rpc.demo.provider;

import com.rpc.demo.common.config.RegisterCenter;
import com.rpc.demo.provider.handler.ProviderNettyHandler;
import com.rpc.demo.provider.server.ProviderNettyServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ZhaoJie
 * @Date: 2022/4/6
 * @Description:
 * @Modify: ===================================================
 * Modifier        Modifytime        Description
 * ===================================================
 */

public class Provider {

    private static Logger logger = LoggerFactory.getLogger(Provider.class);

    private static Map<String, Class> serviceMap = new HashMap<>();

    private static String tcpHost = "127.0.0.1:12000";

    private static ProviderNettyServer providerNettyServer;

    public static void Start(String tcpHost, String serverName) {
        //将服务和服务提供者URL注册到注册中心
        RegisterCenter registerCenter = new RegisterCenter();
        registerCenter.register(serverName, tcpHost);
        String[] split = tcpHost.split(":");
        // 开启netty服务
        providerNettyServer = new ProviderNettyServer();
        providerNettyServer.setProviderHandler(new ProviderNettyHandler());
        providerNettyServer.startServer(split[0], Integer.parseInt(split[1]));

    }

}
